package 笔试.华为;

import jnr.ffi.annotations.In;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class second {
    public static void main(String arg[]){//main--来自高金磊
         Scanner scanner=new Scanner(System.in);
         int n=scanner.nextInt();
         int m=scanner.nextInt();
        LinkedList<int[]> data=new LinkedList<>();
        for (int i = 0; i < m; i++) {
            data.addLast(new int[]{scanner.nextInt(),scanner.nextInt(),scanner.nextInt()});
        }
        Collections.sort(data,(a, b)->(a[2]-b[2]));
        int all_cost=0;
        LinkedList<int[]> middle=new LinkedList<>();
        for (int i = 1; i < n+1; i++) {
            while (true){
                int[] mm=data.pollFirst();
                if (mm[1]<i){
                    //啥也不做
                }
                else {
                    middle.addLast(mm);
                    if (mm[0]<=i){
                        all_cost+=mm[2];
                        break;
                    }
                }
            }
            middle.addAll(data);
            LinkedList<int[]> middle1=middle;
            data.clear();
            middle=data;
            data=middle1;
        }
        System.out.println(all_cost);
    }
}
